/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.awt.Color;
import java.awt.Dimension;
import java.util.ArrayList;
import javax.swing.JPanel;
import model.Kort;
import model.Spiller;
import utility.ImageToolbox;

/**
 *
 * @author Jeppe
 */
public class PlayersHand extends javax.swing.JPanel {

    private ImageToolbox imgTB;
    private MainGui mainGui;
    private Spiller spiller;
    private ArrayList<JPanel> kortPanels;
    /**
     * Creates new form playersHand
     */
    public PlayersHand(MainGui mainGui, Spiller spiller) {
        this.mainGui = mainGui;
        this.spiller = spiller;
        initComponents();
        imgTB = new ImageToolbox();
        kortPanels = new ArrayList<>();
    }

    public void showCardsInPlayersHand() {
        int x = 15;
        jPanel1.removeAll();
        for (int i = 0; i < spiller.getHånd().size(); i++) {
            KortPanel kort = new KortPanel(spiller.getHånd().get(i), new Dimension(146, 205),this);
            kortPanels.add(kort);
            kort.setBounds(x, 0, 146, jPanel1.getSize().height);
            kort.setVisible(true);
            jPanel1.add(kort,0);
            repaint();
            
            x = x + 40;
        }

    }
    
    public void lægKortned (Kort kort){
        if(mainGui.getSpil().lægEtKortned(kort)){
            System.out.println("Kortet er lagt ned");
            mainGui.updateShowHand();
            fejlBesked.setText("");
        }else{
            fejlBesked.setText("Du må ikke lægge det valgte kort ned.");
            fejlBesked.setForeground(Color.RED);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        fejlBesked = new javax.swing.JLabel();
        kortholderLabel = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();

        setOpaque(false);
        setLayout(null);

        fejlBesked.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        add(fejlBesked);
        fejlBesked.setBounds(210, 250, 340, 30);

        kortholderLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Kortholdermindre.png"))); // NOI18N
        add(kortholderLabel);
        kortholderLabel.setBounds(10, 180, 754, 108);

        jPanel1.setOpaque(false);
        jPanel1.setLayout(null);
        add(jPanel1);
        jPanel1.setBounds(110, 20, 560, 205);
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel fejlBesked;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel kortholderLabel;
    // End of variables declaration//GEN-END:variables
}
